﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;

namespace AFT2
{
    [Serializable]
    public class PhoneBookDataObject
    {
        public PhoneBookDataObject(string contactSatus, string name, string hasNum, string inVisibleGroup, string lastTimeContacted, string starred, string timeContacted, string email , string phoneNumber)
        {
            ContactStatus = contactSatus;
            Name = name;
            HasNumber = hasNum;
            InVisibleGroup = inVisibleGroup;
            LastTimeContacted = lastTimeContacted;
            Starred = starred;
            TimesContacted = timeContacted;
            Email = email;
            PhoneNumber = phoneNumber;        
        }
        public string ContactStatus { get; set; }
        public string Name { get; set; }
        public string HasNumber { get; set; }
        public string InVisibleGroup { get; set; }
        public string LastTimeContacted { get; set; }
        public string Starred { get; set; }//favarite
        public string TimesContacted { get; set; }
        public string Email { get; set; }
        public string PhoneNumber { get; set; }
    }


    [Serializable]
    public class PhoneBookDataList
    {
        public PhoneBookDataList()
        {
            this.data = new List<PhoneBookDataObject>();

            SQLiteConnection myConnection = new SQLiteConnection();
            myConnection.ConnectionString = "Data Source=db\\phoneData.db";
            myConnection.Open();
            SQLiteCommand sqlcmd = new SQLiteCommand(myConnection);
            sqlcmd.CommandText = "select * from phonebook;";
            SQLiteDataReader reader = sqlcmd.ExecuteReader();
            while (reader.Read())
            {
                /*
 private static final String CREATE_PHONE_BOOK_TABLE = "create table phonebook("
        + "_id integer primary key autoincrement," 
        + "contact_id text,"
        + "contact_status text,"
        + "name text," 
        + "has_number text," 
        + "in_visible_group text,"
        + "last_time_contacted text,"
        + "starred text,"
        + "times_contacted text," 
        + "email text,"
        + "number text)";
 */

                this.data.Add(
                    new PhoneBookDataObject(
                        "" + reader["contact_status"],
                        "" + reader["name"],
                        "" + reader["has_number"],
                        "" + reader["in_visible_group"],
                        "" + reader["last_time_contacted"],
                        "" + reader["starred"],
                        "" + reader["times_contacted"],
                        "" + reader["email"],
                        "" + reader["number"])
                );
            }

            reader.Close();
            myConnection.Close();
        }

        public List<PhoneBookDataObject> data;
    }
    
}
